package com.uh.checking.filter;

import java.io.File;
import java.io.FilenameFilter;

public class ExcludeMatchFilter implements FilenameFilter {

    private String ext;

    private String prefix;


    public ExcludeMatchFilter(String prefix, String ext) {
        this.ext = "." + ext;
        this.prefix = prefix;
    }

    @Override
    public boolean accept(File dir, String name) {
        if(this.prefix != null && this.ext != null) {
            return !(name.startsWith(this.prefix) && name.endsWith(this.ext));
        }
        else if(this.prefix == null && this.ext != null) {
            return !name.endsWith(this.ext);
        }
        else if(this.prefix != null && this.ext == null) {
            return !name.startsWith(this.prefix);
        }
        else {
            return true;
        }
    }
}
